We've gone over the different aspects of Cricinfo and observed the attributes attached to the problem using various UML diagrams. Let's now explore the more practical side of things, where we will work on implementing the Cricinfo problem using multiple languages. This is usually the last step in an object-oriented design interview process.

We have chosen the following languages to write the skeleton code of the different classes present in Cricinfo:

  • Java

  • C#

  • Python

  • C++

  • JavaScript

Cricinfo classes#

In this section, we will provide the skeleton code of the classes designed in the class diagram lesson.

Note: For simplicity, we are not defining getter and setter functions. The reader can assume that all class attributes are private and accessed through their respective public getter methods and modified only through their public method functions.

Constants#

The following code defines the various enums and custom data types used in the Cricinfo design:

Note: JavaScript does not support enumerations. We’ll usethe Object.freeze() method as an alternative. It freezes an object and prevents further modifications.

Constant definitions

Admin, player, coach, and umpire#

The definitions of the Admin, Player, Coach and Umpire classes are as follows:

The Admin, Player, Coach, and Umpire classes

Run, ball, wicket, over, and innings #

In cricket, the mandatory concepts can be of five types: run, ball, wicket, over, and innings. To store information about these identities, we defined the Run, Ball, Wicket, Over, and Innings classes as shown below:

Implementation of the Run, Ball, Wicket, Over, and Innings classes

Match#

The Match is an abstract class representing matches in Cricinfo. Matches can be of three types: T20, Test, and ODI. The implementation of these classes is given below:

Match and its derived classes

Team, tournament squad, and playing11#

The definitions of the AdminTeam, TournamentSquad, and Playing11 classes are as follows:

The Team, TournamentSquad, and Playing11 classes

Tournament, points table, and stadium#

The definitions of the Tournament, PointsTable, and Stadium classes are as follows:

The Tournament, PointsTable, and Stadium classes

Commentator, commentary, and news#

The definitions of the Commentator, Commentary, and News classes are as follows:

Commentator, Commentary, and News classes

Statistics#

The Stat is an abstract class which represents the statistics in the Cricinfo. Statistics can be of three types: PlayerStat, MatchStat, and TeamStat. These classes are represented below:

Stat and its derived classes

Wrapping up#

We've explored the complete design of Cricinfo in this chapter. We've looked at how Cricinfo can be visualized using various UML diagrams and designed using object-oriented principles and design patterns.

Activity Diagram for Cricinfo

Getting Ready: The LinkedIn System